﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;

namespace FinalProject
{
    public partial class WebForm16 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                InitPage();
            }
        }

        private void InitPage()
        {
            try
            {
                Utility.LoadDropDownList(ref ddlTinhThanh, Utility.LstTinhThanh);
                Utility.LoadDropDownList(ref ddlChucDanh, Utility.LstChucVu);

                string count = Request["count"];

                if (count == "-1")
                {
                    wucNganhNghe.Visible = false;
                    lblAlert.Visible = true;
                }
                else
                {
                    wucNganhNghe.Binding(0);
                }
            }
            catch { }
        }

        private void Binding(ref DropDownList ddl, List<RootObject> lst)
        {
            ddl.DataSource = lst;
            ddl.DataValueField = "ID";
            ddl.DataTextField = "Ten";
            ddl.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string idTinhThanh = "";            
            idTinhThanh = Utility.GetIDRootObject(Utility.LstTinhThanh, ddlTinhThanh.SelectedItem.Text);
            string idChucVu = "";
            idChucVu = Utility.GetIDRootObject(Utility.LstChucVu, ddlChucDanh.SelectedItem.Text);
            string key = tbxInput.Text;

            if (idChucVu == "" && idTinhThanh == "" && key == "")
            {
            }
            else
            {
                Utility.SearchCongViec(key, idTinhThanh, idChucVu);
                wucNganhNghe.Binding(0);

                if (Utility.LstCongViecCurrent != null && Utility.LstCongViecCurrent.Count > 0)
                {
                    wucNganhNghe.Visible = true;
                    lblAlert.Visible = false;
                }
                else
                {
                    wucNganhNghe.Visible = false;
                    lblAlert.Visible = true;
                }
            }
        }
    }
}
